package com.zhongyu.controller;


import com.zhongyu.pojo.Cangku;
import com.zhongyu.pojo.KucunBiandong;
import com.zhongyu.service.CangKuService;
import com.zhongyu.service.KuCunBdService;
import com.zhongyu.vo.CangKuVo;
import com.zhongyu.vo.KuCunBdVo;
import com.zhongyu.vo.PageResult;
import com.zhongyu.vo.ResultVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 库存变动记录
 */
@RestController
@RequestMapping("/kucun/kcbdjl")
public class kuCunBdController {
    @Resource
    private KuCunBdService kuCunBdService;
    @GetMapping("/search/{pageNo}/{pageSize}")
    public ResultVo search(@PathVariable Integer pageNo, @PathVariable Integer pageSize, KuCunBdVo kuCunBdVo){
        PageResult pageResult=kuCunBdService.searchAll(pageNo,pageSize,kuCunBdVo);
        return ResultVo.success(pageResult);

    }
    @GetMapping("/list")
    public ResultVo list() {
        List<KucunBiandong> list = kuCunBdService.searchAll();
        return ResultVo.success(list);

    }
    @GetMapping("/list1")
    public ResultVo list1(Integer cangkuId,Integer goodsId) {
        List<KucunBiandong> list = kuCunBdService.searchById(cangkuId,goodsId);
        return ResultVo.success(list);

    }
    @PostMapping("/update")
    public ResultVo update(@RequestBody KucunBiandong kucunBiandong, HttpSession session) {
        try {
            kuCunBdService.update(kucunBiandong);
            return ResultVo.success("修改库存记录成功!");
        }catch (Exception ex){

            return ResultVo.failure("修改库存记录失败!",ex);
        }
    }

    @GetMapping("/del")
    public ResultVo del(Integer id) {
        try {
            kuCunBdService.del(id);
            return ResultVo.success("删除库存记录成功!");
        } catch (Exception ex) {

            return ResultVo.failure("删除库存记录失败！", ex);
        }
    }
    @PostMapping("/add")
    public ResultVo add(@RequestBody KucunBiandong kucunBiandong, HttpSession session){
        try {
            kuCunBdService.add(kucunBiandong);
            return ResultVo.success("添加库存记录成功!");
        }catch (Exception ex){
            return ResultVo.failure("添加库存记录失败!",ex);
        }
    }
}
